package com.aspire.nm.component.cmppserver.runTime;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;


@Scope("prototype")
@Component
public class SpeedController {
	
	private  int sendtmpCount = 0;
	private  long tmpl=System.currentTimeMillis();
	
	public  boolean isTimeLimitInSecond(int maxSendInSecond,boolean sleep)
	{
		if (++sendtmpCount >= maxSendInSecond)
	    {
	      long l = System.currentTimeMillis() - tmpl;
	      if (l < 1000){
			try {
				if(sleep)
				Thread.sleep(1000 - l);
				return true;
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
	      }
	      sendtmpCount = 1;
    	  tmpl = System.currentTimeMillis();
	    }
		return false;
	  }
}
